﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using TSSTaskBasicClass;
using System.Reflection;
using System.Windows.Forms;
using System.Drawing;
using System.Diagnostics;
using TaskSchedulingSystemForm.Model;

namespace TaskSchedulingSystemForm
{
    static class TaskScheduling
    {   
        /// <summary>
        /// 调度程序自动调度任务
        /// </summary>
        /// <param name="config"></param>
        /// <param name="tabControl"></param>
        public static void DoTaskScheduling(object o)
        {
            TaskModel task = o as TaskModel;
            Console.WriteLine("开始创建线程！");
            task.isRunTask = true;
            ABasicTaskWork ta = (ABasicTaskWork)Assembly.Load("TaskSchedulingSystemForm").CreateInstance(task.taskClass);
            Thread thread = new Thread(new ParameterizedThreadStart(ta.DoTaskWork));
            thread.Name = task.taskName;
            task.taskThreadId = thread.ManagedThreadId;
            MainForm.CarryNowTaskIdPool.Add(task.taskThreadId, false);
            MainForm.taskCarryNowLst.Add(task);
            thread.Start(task);
        }
    }
}
